﻿using Aker.Cikislar;
using Aker.DevTeam;
using Aker.Hammadde;
using Aker.MainForms;
using Aker.Product;
using Aker.Sistem;
using Aker.Tanimlar;
using Aker.Uretim;
using DevExpress.XtraBars;
using DevExpress.XtraBars.Ribbon;
using DevExpress.XtraEditors;
using DevExpress.XtraGrid.Views.Grid.Customization;
using DevTeam;
using System;
using System.Collections.Generic;
using System.Data;
using System.IO.Ports;
using System.Windows.Forms;


namespace Aker
{
    public partial class MainForm : RibbonForm
    {
        public int WhoAmI;
        public XForm ActiveXForm = null;
        public Pidion.Device black = new Pidion.Device();


        public MainForm()
        {
            InitializeComponent();
        }

        #region Bluetooth
        System.IO.Ports.SerialPort blue;
        System.IO.Ports.SerialPort blackNew;
        delegate void OnBarcodeReadHandler(int text);

        byte[] del = new byte[] { 0x7e, 0x31, 0x00, 0x00, 0x8f, 0x02, 0x00, 0x01, 0x04, 0x00, 0x00 };   //cihazın üzerinde tuttuğu veriyi silmek için gereken komut
        byte[] ack = new byte[] { 0x7e, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00 };               //client'ın göndermesi gereken konfirmasyon        
        byte[] delAck = new byte[] { 126, 49, 0, 0, 15, 1, 0, 0, 0, 0 };


        #endregion

        #region ShowForm
        public XForm GetActiveForm(Type type, params object[] prm)
        {
            XForm frm;
            string hash = GetHash(type, prm);

            forms.TryGetValue(hash, out frm);

            if (frm != null)
                if (!frm.IsDisposed)
                {
                    frm.Activate();
                    return frm;
                }
                else
                    forms.Remove(hash);

            return null;
        }

        public List<XForm> GetFormOfType(Type type)
        {
            List<XForm> frms = new List<XForm>();
            foreach (XForm x in forms.Values)
                if (x.GetType() == type && x != null && !x.IsDisposed)
                    frms.Add(x);

            return frms;
        }

        public Dictionary<string, XForm> forms = new Dictionary<string, XForm>();

        private string GetHash(Type type, object[] prm)
        {
            string prmHash = "";
            foreach (object o in prm)
                prmHash += o.GetHashCode();

            return type.GetHashCode() + "." + prmHash;
        }

        public XForm ShowMdiChildForm(Type type, params object[] prm)
        {
            this.Cursor = Cursors.WaitCursor;
            XForm frm = GetActiveForm(type, prm);

            if (frm != null)
            {
                ActiveXForm = frm;
                this.Cursor = Cursors.Default;
                return frm;
            }

            try
            {
                if (type.BaseType == typeof(XPopupForm))
                {
                    using (XPopupForm popup = (XPopupForm)Activator.CreateInstance(type, prm))
                    {
                        ActiveXForm = popup;
                        frm = popup;
                        popup.ShowDialog();
                    }
                }
                else
                {
                    frm = (XForm)Activator.CreateInstance(type, prm);
                    frm.MdiParent = tabbedView.Manager.MdiParent;
                    frm.WindowState = FormWindowState.Maximized;
                    string hash = GetHash(type, prm);
                    forms.Add(hash, frm);
                    ActiveXForm = frm;
                    frm.Show();

                }
            }
            catch (Exception Ex)
            {
                this.Cursor = Cursors.Default;
                LogManager.LogToDB(Ex);
            }

            this.Cursor = Cursors.Default;
            return frm;
        }


        #endregion

        private void MainForm_KeyDown(object sender, KeyEventArgs e)
        {
            if (e.KeyCode == Keys.F12 && e.Control)
            {

            }
        }

        public void SetActiveXFormFromMDIManager()
        {
            //DockManagerUpdate+
            if (tabbedView.ActiveDocument == null)
                ActiveXForm = null;
            else
            {
                XForm activeForm = tabbedView.ActiveDocument.Form as XForm;
                ActiveXForm = activeForm;
            }
        }

        private void mdiManager_SelectedPageChanged(object sender, EventArgs e)
        {
            SetActiveXFormFromMDIManager();
        }



        public string Info
        {
            set
            {
                string message = value;
                message = message.Replace("\r\n", " ");
                lblInfo.Caption = "[" + DateTime.Now.ToString("HH:mm:ss") + "] " + message;
            }
        }


        string Caption;

        private void MainForm_Load(object sender, EventArgs e)
        {

            DevExpress.Data.CurrencyDataController.DisableThreadingProblemsDetection = true;

            Settings.Init();
            UserSettings.Init();
            Language.Init();

            this.Caption = this.Text;
            bbiDil.EditValueChanged += bbiDil_EditValueChanged;
            bbiDil.EditValue = AppSession.Language;


            if (AppSession.IsOnline)
            {
                this.Text = Caption + Language.MainForm.Online;
                btnFairSync.Visibility = BarItemVisibility.Never;
            }
            else
            {
                string info = Data.DB.Setting.FindBySettingId(14).Value.ToStringNN();
                if (info != "")
                    info = Language.MainForm.UpdatedOn + info;

                this.Text = Caption + Language.MainForm.Offline + info + " ]";
                btnPrepareFair.Visibility = BarItemVisibility.Never;
                btnFairReports.Visibility = BarItemVisibility.Never;
            }

            if (AppSession.IsTest && Data.DM.ConnectionString.Contains("Catalog=AkerTest"))
                this.Text += " ***** TEST *****";

            if (!AppSession.UserInfo.Yonetici)
                btnUsers.Visibility = BarItemVisibility.Never;

            btnFairNewOrder.ItemClick += btnNewOrder_ItemClick;
            btnFairOrders.ItemClick += btnOrders_ItemClick;
            btnArtikeller.ItemClick += btnProducts_ItemClick;
            btnFairSync.ItemClick += btnSync_ItemClick;
            btnFairSendEmail.ItemClick += btnSendEmail_ItemClick;

            this.KeyDown += MainForm_KeyDown;

            FormClosing += new FormClosingEventHandler(MainForm_FormClosing);


            ribbon.ToolbarLocation = RibbonQuickAccessToolbarLocation.Hidden;

            btnConnect.PerformClick();

            AppSession.MainForm.ShowInTaskbar = true;
            AppSession.MainForm.WindowState = FormWindowState.Maximized;

            Data.RefreshData();

            rpProduction.Visible = true;


            if (AppSession.UserInfo.YetkiId == 1)
            {
                ribbon.Pages[0].Text = Language.MainForm.Warehouse;
                //btnNewOrder.Visibility = BarItemVisibility.Never;
                btnSettings.Visibility = BarItemVisibility.Never;
                btnKisaltmalar.Visibility = BarItemVisibility.Never;
                btnUsers.Visibility = BarItemVisibility.Never;
                btnFairSync.Visibility = BarItemVisibility.Never;
                btnFairSendEmail.Visibility = BarItemVisibility.Never;
                btnPrepareFair.Visibility = BarItemVisibility.Never;
                btnFairReports.Visibility = BarItemVisibility.Never;
                btnQuery.Visibility = BarItemVisibility.Never;
            }
            else if (AppSession.UserInfo.YetkiId == 2)
            {
                ribbon.Pages[0].Text = Language.MainForm.WarehouseAdmin;
                //btnNewOrder.Visibility = BarItemVisibility.Never;
                btnSettings.Visibility = BarItemVisibility.Never;
                btnKisaltmalar.Visibility = BarItemVisibility.Never;
                btnUsers.Visibility = BarItemVisibility.Never;
                btnFairSync.Visibility = BarItemVisibility.Never;
                btnFairSendEmail.Visibility = BarItemVisibility.Never;
                btnPrepareFair.Visibility = BarItemVisibility.Never;
                btnQuery.Visibility = BarItemVisibility.Never;
            }
            else if (AppSession.UserInfo.YetkiId == 3)
            {
                ribbon.Pages[0].Text = Language.MainForm.Marketing;
                //btnNewOrder.Visibility = BarItemVisibility.Never;
                //btnSettings.Visibility = BarItemVisibility.Never;
                btnKisaltmalar.Visibility = BarItemVisibility.Never;
                btnUsers.Visibility = BarItemVisibility.Never;
                btnFairSync.Visibility = BarItemVisibility.Never;
                btnFairSendEmail.Visibility = BarItemVisibility.Never;
                btnPrepareFair.Visibility = BarItemVisibility.Never;
                //btnProducts.Visibility = BarItemVisibility.Never;
                btnToplar.Visibility = BarItemVisibility.Never;
                btnQuery.Visibility = BarItemVisibility.Never;
            }
            else if (AppSession.UserInfo.YetkiId == 4)
            {
                ribbon.Pages[0].Text = Language.MainForm.MarketingAdmin;
                //btnNewOrder.Visibility = BarItemVisibility.Never;
                //btnSettings.Visibility = BarItemVisibility.Never;
                btnKisaltmalar.Visibility = BarItemVisibility.Never;
                btnUsers.Visibility = BarItemVisibility.Never;
                btnFairSync.Visibility = BarItemVisibility.Never;
                btnFairSendEmail.Visibility = BarItemVisibility.Never;
                btnPrepareFair.Visibility = BarItemVisibility.Never;
                btnToplar.Visibility = BarItemVisibility.Never;
                btnQuery.Visibility = BarItemVisibility.Never;
            }
            else if (AppSession.UserInfo.YetkiId == 5)
            {
                ribbon.Pages[0].Text = Language.MainForm.Admin;
                btnQuery.Visibility = BarItemVisibility.Always;
                //rpProduction.Visible = true;
            }

            if (Environment.MachineName == "KGULCAN")
            {
                btnExcel.Visibility = BarItemVisibility.Always;
            }

            tabbedView.DocumentActivated += tabbedView_DocumentActivated;
            tabbedView.DocumentGroupProperties.PinPageButtonShowMode = DevExpress.XtraTab.PinPageButtonShowMode.InActiveTabPageHeader;
        }

        void tabbedView_DocumentActivated(object sender, DevExpress.XtraBars.Docking2010.Views.DocumentEventArgs e)
        {
            SetActiveXFormFromMDIManager();

            if (tabbedView.ActiveDocument != null)
            {
                XForm activeForm = tabbedView.ActiveDocument.Form as XForm;

                foreach (DevExpress.XtraBars.Docking2010.Views.BaseDocument doc in tabbedView.Documents)
                {
                    XForm form = doc.Form as XForm;
                    if (form != null && form != activeForm)
                    {
                        foreach (CustomizationForm cf in form.CustomizationForms)
                            cf.Hide();
                    }
                }

                if (activeForm != null)
                {
                    foreach (CustomizationForm cf in activeForm.CustomizationForms)
                        if (!cf.IsDisposed)
                            cf.Show();
                }
            }
        }

        void bbiDil_EditValueChanged(object sender, EventArgs e)
        {
            AppSession.Language = bbiDil.EditValue.ToStringNN();
            //Language.Init(); 

            //btnFairNewOrder.Caption = Language.MainForm.NewOrder;
            //btnFairOrders.Caption = Language.MainForm.FairOrders;
            //btnArtikeller.Caption = Language.MainForm.Products;
            //btnKisaltmalar.Caption = Language.MainForm.Construction;
            ////btnToplar.Caption = Language.MainForm.Stock;
            //btnConnect.Caption = Language.MainForm.Connect;
            //btnFairSync.Caption = Language.MainForm.SyncNewOrders;
            //btnFairSendEmail.Caption = Language.MainForm.SendNewEmails;
            //btnSettings.Caption = Language.MainForm.Settings;
            //btnFairReports.Caption = Language.MainForm.Reports;
            //btnPrepareFair.Caption = Language.MainForm.PrepareFair;
            //btnUsers.Caption = Language.MainForm.Users;

            ////rpProduction.Text = Language.MainForm.ProductionOrders;
            //btnNewPOrder.Caption = Language.MainForm.NewProductionOrder;
            //btnPOrders.Caption = Language.MainForm.ProductionOrders;
            //btnTransfers.Caption = Language.MainForm.Transfers;
            //btnTransferReport.Caption = Language.MainForm.TransferReports;
            //btnCustomer.Caption = Language.MainForm.Customers;
            //btnCustomersAndFairVisitors.Caption = Language.MainForm.CustomersAndVisitors;

            //btnFile.Caption = Language.MainForm.FromFile;
            //btnServer.Caption = Language.MainForm.FromServer;
            //btnAppSettings.Caption = Language.MainForm.AppSettings;
            //userSettings.Caption = Language.MainForm.UserSettings;


            //grpMain.Text = Language.MainForm.Actions;


            if (AppSession.IsOnline)
                this.Text = Caption + Language.MainForm.Online;
            else
            {
                string info = Data.DB.Setting.FindBySettingId(14).Value.ToStringNN();
                if (info != "")
                    info = Language.MainForm.UpdatedOn + info;

                this.Text = Caption + Language.MainForm.Offline + info + " ]";
            }


            if (AppSession.UserInfo.YetkiId == 1)
                ribbon.Pages[0].Text = Language.MainForm.Warehouse;
            else if (AppSession.UserInfo.YetkiId == 2)
                ribbon.Pages[0].Text = Language.MainForm.WarehouseAdmin;
            else if (AppSession.UserInfo.YetkiId == 3)
                ribbon.Pages[0].Text = Language.MainForm.Marketing;
            else if (AppSession.UserInfo.YetkiId == 4)
                ribbon.Pages[0].Text = Language.MainForm.MarketingAdmin;
            else if (AppSession.UserInfo.YetkiId == 5)
                ribbon.Pages[0].Text = Language.MainForm.Admin;
        }





        private void MainForm_FormClosing(object sender, FormClosingEventArgs e)
        {
            try
            {
                if (blackConnected)
                    black.Disconnect();

                if (blueConnected)
                    blue.Close();
            }
            catch { }
        }


        void black_BarcodeRead(int Barcode)
        {
            if (Barcode > 0)
            {
                Info = "Black.ProductId: " + Barcode.ToString();

                if (ActiveXForm != null)
                    ActiveXForm.FireBarcodeRead(Barcode);
            }
        }


        string lastData = "";
        private void blue_DataReceived(object sender, SerialDataReceivedEventArgs e)
        {
            string s1 = "";

            try
            {
                int bytesToRead = blue.BytesToRead;
                byte[] buffer = new byte[bytesToRead];
                blue.Read(buffer, 0, bytesToRead);

                s1 = blue.Encoding.GetString(buffer);
                if (!s1.Contains("\r\n"))
                {
                    lastData += s1;
                    return;
                }
                else
                {
                    string s2 = s1.Replace("\r\n", "");

                    s2 = lastData + s2;
                    lastData = "";

                    string s3 = s2.TrimStart(new char[] { '0' });
                    string s4 = s3.Substring(0, s3.Length - 1);


                    int barcode = 0;
                    int.TryParse(s4, out barcode);

                    if (barcode > 0)
                    {
                        Info = "Blue.Barcode: " + barcode.ToString();

                        if (ActiveXForm != null)
                            ActiveXForm.FireBarcodeRead(barcode);
                    }
                    else
                        Info = "Blue.Barcode.ERROR:" + s4;
                }

                //if (AppSession.UserInfo.UserId == 2)
                //{
                //    Info = "KG:" + portData + "(" + portData.Length.ToString() + "-" + bytesToRead.ToString() + ")";
                //}

                //if (portData.Length > 3)
                //{
                //    int productId = 0;
                //    int.TryParse(portData.Substring(0, portData.Length - 3), out productId);

                //    if (productId > 0)
                //    {
                //        Info = "Blue.PortData: " + portData + "(" + portData.Length.ToString() + "-" + bytesToRead.ToString() + ")" + " | Blue.ProductId: " + productId.ToString();

                //        if (ActiveXForm != null)
                //            ActiveXForm.FireBarcodeRead(productId);
                //    }
                //    else
                //    {
                //        Info = "KG:" + portData + "(" + portData.Length.ToString() + "-" + bytesToRead.ToString() + ")";
                //    }
                //}
                //else if (AppSession.UserInfo.UserId == 2)
                //{
                //    Info = "EXC:" + portData + "(" + portData.Length.ToString() + "-" + bytesToRead.ToString() + ")";
                //}



            }
            catch (Exception ex)
            {
                Info = "Blue.PortData:" + s1 + "- EXC:" + ex.ToStringNN();
            }



        }

        #region Buttons
        private void btnProducts_ItemClick(object sender, ItemClickEventArgs e)
        {
            ShowMdiChildForm(typeof(Products));
        }


        private void btnNewOrder_ItemClick(object sender, ItemClickEventArgs e)
        {
            Orders orders = (Orders)ShowMdiChildForm(typeof(Orders));
            orders.AddNewOrder();
        }

        private void btnOrders_ItemClick(object sender, ItemClickEventArgs e)
        {
            ShowMdiChildForm(typeof(Orders));
        }


        private void btnSync_ItemClick(object sender, ItemClickEventArgs e)
        {
            this.Cursor = Cursors.WaitCursor;
            Data.SaveOrder();

            DataRow[] drs = Data.DB.Order.Select("SyncDate is null");
            Info = Data.Sync(drs);

            this.Cursor = Cursors.Default;
        }

        private void btnSendEmail_ItemClick(object sender, ItemClickEventArgs e)
        {
            this.Cursor = Cursors.WaitCursor;
            Data.SaveOrder();

            DataRow[] drs = Data.DB.Order.Select("eMailDate is null");

            Info = Data.SendEmail(drs);
            this.Cursor = Cursors.Default;
        }


        #endregion

        private void btnReports_ItemClick(object sender, ItemClickEventArgs e)
        {
            this.Cursor = Cursors.WaitCursor;
            ShowMdiChildForm(typeof(Reports));
            this.Cursor = Cursors.Default;
        }


        private static bool ConfirmOffline()
        {
            System.Windows.Forms.DialogResult dr = XtraMessageBox.Show(Language.MainForm.ConfirmOffline, Language.Uyari, MessageBoxButtons.YesNo, MessageBoxIcon.Warning);


            return dr == DialogResult.Yes;
        }

        private void btnUsers_ItemClick(object sender, ItemClickEventArgs e)
        {
            ShowMdiChildForm(typeof(Users));
        }

        private void btnKisaltmalar_ItemClick(object sender, ItemClickEventArgs e)
        {
            ShowMdiChildForm(typeof(Kisaltmalar));
        }

        private void btnStock_ItemClick(object sender, ItemClickEventArgs e)
        {
            ShowMdiChildForm(typeof(ArtikelStokVeCikis));
        }

        bool blackConnected = false;
        bool blueConnected = false;
        bool blackNewConnected = false;

        private void btnConnect_ItemClick(object sender, ItemClickEventArgs e)
        {
            int blackComPort = Settings.BlackComPort.ToIntNN();
            int blueComPort = Settings.BlueComPort.ToIntNN();
            int blackNewComPort = Settings.BlackNewComPort.ToIntNN();
            string blackResult = string.Empty;
            string blueResult = string.Empty;


            if (blackComPort != -1)
            {
                black.Disconnect();

                blackResult = black.Connect(blackComPort);
                if (blackResult == "SUCCESS")
                {
                    blackResult = "BLACK : OK";
                    black.BarcodeRead += black_BarcodeRead;
                    blackConnected = true;
                }
                else
                {
                    blackResult = "BLACK : ERR !!! " + blackResult;
                }
            }

            if (blueComPort != -1)
            {
                blueResult = "BLUE : OK";

                try
                {
                    blue = new System.IO.Ports.SerialPort("COM" + blueComPort);
                    blue.BaudRate = 57600;
                    blue.DataBits = 8;
                    blue.Parity = System.IO.Ports.Parity.None;
                    blue.StopBits = StopBits.One;
                    blue.Handshake = Handshake.None;
                    blue.DtrEnable = true;

                    blue.Close();
                    blue.Open();

                    blue.DataReceived += blue_DataReceived;
                    //port.Write(del, 0, del.Length); // clear inline reader memory

                    Info = Language.MainForm.Connected;
                    blueConnected = true;
                }
                catch (Exception ex)
                {
                    blueResult = "BLUE : ERR !!! " + ex.Message;
                }
            }

            if (blackNewComPort != -1)
            {
                blueResult = "Black New : OK";

                try
                {
                    blackNew = new System.IO.Ports.SerialPort("COM" + blackNewComPort);
                    blackNew.BaudRate = 57600;
                    blackNew.DataBits = 8;
                    blackNew.Parity = System.IO.Ports.Parity.None;
                    blackNew.StopBits = StopBits.One;
                    blackNew.Handshake = Handshake.None;
                    blackNew.DtrEnable = true;

                    blackNew.Close();
                    blackNew.Open();

                    blackNew.DataReceived += blackNew_DataReceived;
                    //port.Write(del, 0, del.Length); // clear inline reader memory

                    Info = Language.MainForm.Connected;
                    blueConnected = true;
                }
                catch (Exception ex)
                {
                    blueResult = "BLUE : ERR !!! " + ex.Message;
                }
            }

            List<string> infos = new List<string>();


            if (blackResult != "")
                infos.Add(blackResult);
            if (blueResult != "")
                infos.Add(blueResult);

            infos.Add("Artikeller yükleniyor...");

            Info = string.Join(" - ", infos);
        }

        string blackNewDownload = "";

        void blackNew_DataReceived(object sender, SerialDataReceivedEventArgs e)
        {
            string s1 = "";

            try
            {
                int bytesToRead = blackNew.BytesToRead;
                byte[] buffer = new byte[bytesToRead];
                blackNew.Read(buffer, 0, bytesToRead);

                s1 = blackNew.Encoding.GetString(buffer);

                if (!s1.StartsWith("Total"))    //Downloading...
                    blackNewDownload += s1;
                else                            //Uploading statistics
                {
                    int totalBarcodes = s1.Replace("\0", "").Replace("Total Counters = ", "").Replace("\r\n", "").ToIntNN();
                    XtraMessageBox.Show(totalBarcodes + " barkod okundu...");

                    string[] vals = blackNewDownload.Split("\r\n".ToCharArray(), StringSplitOptions.RemoveEmptyEntries);

                    blackNewDownload = "";
                    Dictionary<int, int> result = new Dictionary<int, int>();

                    int lastShelfId = 0;
                    foreach (string val in vals)
                    {
                        try
                        {
                            string s3 = val.TrimStart(new char[] { '0' });
                            string s4 = s3.Substring(0, s3.Length - 1);


                            int barcode = int.Parse(s4);

                            if (barcode > 1000000 && barcode < 2000001)
                            {
                                lastShelfId = barcode;
                            }
                            else if (barcode > 2000000 && barcode < 3000001)
                            {
                                if (lastShelfId > 0)
                                {
                                    if (result.ContainsKey(barcode))
                                        result.Remove(barcode);

                                    result.Add(barcode, lastShelfId);
                                }
                            }
                        }
                        catch (Exception ex)
                        {
                            XtraMessageBox.Show("HATA: [" + val + "] - " + ex.ToString());
                            LogManager.LogToDB(ex);
                        }
                    }


                    if (Data.DB.StokLines.Count == 0)
                        Data.TAM.StokLinesTableAdapter.Fill(Data.DB.StokLines);

                    foreach (KeyValuePair<int, int> pair in result)
                    {
                        //XtraMessageBox.Show("RollId:" + pair.Key + " , ShelfId:" + pair.Value);
                        AkerDB.StokLinesRow slRow = (AkerDB.StokLinesRow)Data.DB.StokLines.Select("RollId = " + pair.Key)[0];
                        slRow.ShelfId = pair.Value;
                        Data.TAM.StokLinesTableAdapter.Update(slRow);
                    }

                    XtraMessageBox.Show(result.Count + " top raflandı...");
                }


            }
            catch (Exception ex)
            {
                Info = "BlackNew.PortData:" + s1 + "- EXC:" + ex.ToStringNN();
                LogManager.LogToDB(ex);
            }
        }

        private void btnServer_ItemClick(object sender, ItemClickEventArgs e)
        {
            if (ConfirmOffline())
            {
                this.Cursor = Cursors.WaitCursor;
                Data.PrepareOfflineFromServer();
                this.Cursor = Cursors.Default;
            }
        }

        private void btnFile_ItemClick(object sender, ItemClickEventArgs e)
        {
            if (ConfirmOffline())
            {
                this.Cursor = Cursors.WaitCursor;
                OpenFileDialog ofd = new OpenFileDialog();
                ofd.Filter = "SQL Server Backup File|*.bak";
                if (ofd.ShowDialog() == System.Windows.Forms.DialogResult.OK)
                    Data.PrepareOfflineFromFile(ofd.FileName);
                this.Cursor = Cursors.Default;
            }
        }

        private void userSettings_ItemClick(object sender, ItemClickEventArgs e)
        {
            ShowMdiChildForm(typeof(UserSettings));
        }

        private void btnAppSettings_ItemClick(object sender, ItemClickEventArgs e)
        {
            ShowMdiChildForm(typeof(Settings));
        }

        private void btnGrup1_ItemClick(object sender, ItemClickEventArgs e)
        {
            ShowMdiChildForm(typeof(YeniImalatKarti1));
        }

        private void btnGrup2_ItemClick(object sender, ItemClickEventArgs e)
        {
            ShowMdiChildForm(typeof(YeniImalatKarti2));
        }

        private void btnPOrders_ItemClick(object sender, ItemClickEventArgs e)
        {
            ShowMdiChildForm(typeof(Uretim.Siparisler));
        }



        private void btnNewPOrder_ItemClick(object sender, ItemClickEventArgs e)
        {
            ShowMdiChildForm(typeof(Products));
        }

        private void btnCustomer_ItemClick(object sender, ItemClickEventArgs e)
        {
            ShowMdiChildForm(typeof(Order.Customer));
        }

        private void CustomersAndFairVisitors_ItemClick(object sender, ItemClickEventArgs e)
        {
            ShowMdiChildForm(typeof(Order.CustomersAndFairVisitors));
        }

        private void btnTasks_ItemClick(object sender, ItemClickEventArgs e)
        {
            ShowMdiChildForm(typeof(Task));
        }

        private void btnElyaf_ItemClick(object sender, ItemClickEventArgs e)
        {
            ShowMdiChildForm(typeof(Elyaf));
        }

        private void btnIplik_ItemClick(object sender, ItemClickEventArgs e)
        {
            ShowMdiChildForm(typeof(Hammadde.Iplik));
        }

        private void btnHammaddeCikis_ItemClick(object sender, ItemClickEventArgs e)
        {
            ShowMdiChildForm(typeof(HammaddeCikis));
        }

        private void btnStok_ItemClick(object sender, ItemClickEventArgs e)
        {
            ShowMdiChildForm(typeof(HammaddeStok));
        }

        private void btnYeniTransfer_ItemClick(object sender, ItemClickEventArgs e)
        {
            ShowMdiChildForm(typeof(Aker.Uretim.SiparisTakipVeCikis));
        }

        private void btnExcel_ItemClick(object sender, ItemClickEventArgs e)
        {
            using (OpenFileDialog ofd = new OpenFileDialog())
            {

                if (ofd.ShowDialog() == System.Windows.Forms.DialogResult.OK)
                {
                    //ElyafEkle(ofd);
                    //IplikEkle(ofd);
                }
            }

        }

        //private static void IplikEkle(OpenFileDialog ofd)
        //{
        //    DataSet dsIplik = Data.DM.ExecuteDataSet("GetDSIplik");

        //    using (ExcelPackage pack = new ExcelPackage(new FileInfo(ofd.FileName)))
        //    {
        //        ExcelWorksheet ws = pack.Workbook.Worksheets[1];
        //        ExcelRange cells = ws.Cells;

        //        object[,] vals = (object[,])cells.Value;


        //        int row = vals.GetLength(0);
        //        int col = vals.GetLength(1);


        //        for (int rowIndex = 2; rowIndex < row + 1; rowIndex++)
        //        {
        //            System.Diagnostics.Debug.WriteLine(rowIndex.ToString());
        //            string val = cells[rowIndex, 1].Value.ToStringNN().Trim();


        //            string kalinlik = cells[rowIndex, 2].Value.ToStringNN().Trim();
        //            string fKalinlik = "";

        //            if (kalinlik != "")
        //                fKalinlik = "Kalinlik = '" + kalinlik + "'";
        //            else
        //                fKalinlik = "Kalinlik is null";



        //            val = cells[rowIndex, 3].Value.ToStringNN().Trim();
        //            int karisimId1 = -1;
        //            string fKarisimId1 = "";

        //            if (val != "")
        //            {
        //                karisimId1 = dsIplik.Tables[0].Select("Karisim = '" + val + "'")[0][0].ToIntNN();
        //                fKarisimId1 = "IplikKarisimId1 = " + karisimId1;
        //            }
        //            else
        //                fKarisimId1 = "IplikKarisimId1 is null";

        //            int oran1 = cells[rowIndex, 4].Value.ToIntNN();
        //            string fOran1 = "";

        //            if (oran1 > -1)
        //                fOran1 = "IplikKarisimOrani1 = '" + oran1 + "'";
        //            else
        //                fOran1 = "IplikKarisimOrani1 is null";



        //            val = cells[rowIndex, 5].Value.ToStringNN().Trim();
        //            int karisimId2 = -1;
        //            string fKarisimId2 = "";

        //            if (val != "")
        //            {
        //                karisimId2 = dsIplik.Tables[0].Select("Karisim = '" + val + "'")[0][0].ToIntNN();
        //                fKarisimId2 = "IplikKarisimId2 = " + karisimId2;
        //            }
        //            else
        //                fKarisimId2 = "IplikKarisimId2 is null";

        //            int oran2 = cells[rowIndex, 6].Value.ToIntNN();
        //            string fOran2 = "";

        //            if (oran2 > -1)
        //                fOran2 = "IplikKarisimOrani2 = '" + oran2 + "'";
        //            else
        //                fOran2 = "IplikKarisimOrani2 is null";



        //            val = cells[rowIndex, 7].Value.ToStringNN().Trim();
        //            int karisimId3 = -1;
        //            string fKarisimId3 = "";

        //            if (val != "")
        //            {
        //                karisimId3 = dsIplik.Tables[0].Select("Karisim = '" + val + "'")[0][0].ToIntNN();
        //                fKarisimId3 = "IplikKarisimId3 = " + karisimId3;
        //            }
        //            else
        //                fKarisimId3 = "IplikKarisimId3 is null";

        //            int oran3 = cells[rowIndex, 8].Value.ToIntNN();
        //            string fOran3 = "";

        //            if (oran3 > -1)
        //                fOran3 = "IplikKarisimOrani3 = '" + oran3 + "'";
        //            else
        //                fOran3 = "IplikKarisimOrani3 is null";




        //            val = cells[rowIndex, 9].Value.ToStringNN().Trim();
        //            int parlaklikId = -1;
        //            string fParlaklikId = "";


        //            if (val != "")
        //            {
        //                parlaklikId = dsIplik.Tables[1].Select("Parlaklik = '" + val + "'")[0][0].ToIntNN();
        //                fParlaklikId = "IplikParlaklikId = " + parlaklikId;
        //            }
        //            else
        //                fParlaklikId = "IplikParlaklikId is null";




        //            string elyafOzelligi = cells[rowIndex, 10].Value.ToStringNN().Trim();
        //            string fElyafOzelligi = "";

        //            if (elyafOzelligi != "")
        //                fElyafOzelligi = "ElyafOzelligi = '" + elyafOzelligi + "'";
        //            else
        //                fElyafOzelligi = "ElyafOzelligi is null";




        //            val = cells[rowIndex, 11].Value.ToStringNN().Trim();
        //            int iplikCekmeTipiId = -1;
        //            string fIplikCekmeTipiId = "";

        //            if (val != "")
        //            {
        //                iplikCekmeTipiId = dsIplik.Tables[2].Select("CekmeTipi = '" + val + "'")[0][0].ToIntNN();
        //                fIplikCekmeTipiId = "IplikCekmeTipiId = " + iplikCekmeTipiId;
        //            }
        //            else
        //                fIplikCekmeTipiId = "IplikCekmeTipiId is null";


        //            val = cells[rowIndex, 12].Value.ToStringNN().Trim();
        //            int iplikCekimId = -1;
        //            string fIplikCekimId = "";

        //            if (val != "")
        //            {
        //                iplikCekimId = dsIplik.Tables[3].Select("Cekim = '" + val + "'")[0][0].ToIntNN();
        //                fIplikCekimId = "IplikCekimId = " + iplikCekimId;
        //            }
        //            else
        //                fIplikCekimId = "IplikCekimId is null";





        //            string fantazi = cells[rowIndex, 13].Value.ToStringNN().Trim();
        //            string fFantazi = "";

        //            if (fantazi != "")
        //                fFantazi = "Fantazi = '" + fantazi + "'";
        //            else
        //                fFantazi = "Fantazi is null";




        //            string aciklama = cells[rowIndex, 14].Value.ToStringNN().Trim();
        //            string faciklama = "";

        //            if (aciklama != "")
        //                faciklama = "Aciklama = '" + aciklama + "'";
        //            else
        //                faciklama = "Aciklama is null";



        //            string sql = "select * from IplikGrup where " + fKalinlik + " and " + fKarisimId1 + " and " + fOran1 + " and " + fKarisimId2 + " and " + fOran2 + " and " + fKarisimId3 + " and " + fOran3
        //                + " and " + fParlaklikId
        //                + " and " + fElyafOzelligi
        //                + " and " + fIplikCekmeTipiId
        //                + " and " + fIplikCekimId
        //                + " and " + fFantazi
        //                + " and " + faciklama;


        //            int iplikGrupId = -1;


        //            DataTable dt = Data.DM.ExecuteDataTableByQuery(sql);
        //            if (dt.Rows.Count == 1)
        //                iplikGrupId = dt.Rows[0]["IplikGrupId"].ToIntNN();
        //            else
        //            {
        //                sql = "insert into IplikGrup(Aciklama) select null select SCOPE_IDENTITY()";
        //                iplikGrupId = Data.DM.ExecuteDataTableByQuery(sql).Rows[0][0].ToIntNN();


        //                sql = "update IplikGrup set GrupKodu='IP." + iplikGrupId.ToString().PadLeft(3, '0') + "'";


        //                if (kalinlik != "")
        //                    sql += " , Kalinlik='" + kalinlik + "'";

        //                if (karisimId1 != -1)
        //                    sql += " , IplikKarisimId1=" + karisimId1;

        //                if (karisimId2 != -1)
        //                    sql += " , IplikKarisimId2=" + karisimId2;

        //                if (karisimId3 != -1)
        //                    sql += " , IplikKarisimId3=" + karisimId3;


        //                if (oran1 != -1)
        //                    sql += " , IplikKarisimOrani1=" + oran1;

        //                if (oran2 != -1)
        //                    sql += " , IplikKarisimOrani2=" + oran2;

        //                if (oran3 != -1)
        //                    sql += " , IplikKarisimOrani3=" + oran3;


        //                if (parlaklikId != -1)
        //                    sql += " , IplikParlaklikId=" + parlaklikId;

        //                if (elyafOzelligi != "")
        //                    sql += " , ElyafOzelligi='" + elyafOzelligi + "'";

        //                if (iplikCekmeTipiId != -1)
        //                    sql += " , IplikCekmeTipiId=" + iplikCekmeTipiId;


        //                if (iplikCekimId != -1)
        //                    sql += " , IplikCekimId=" + iplikCekimId;

        //                if (fantazi != "")
        //                    sql += " , Fantazi='" + fantazi + "'";

        //                if (aciklama != "")
        //                    sql += " , aciklama='" + aciklama + "'";

        //                sql += " where IplikGrupId =" + iplikGrupId;
        //                Data.DM.ExecuteDataTableByQuery(sql);
        //            }


        //            string kod = cells[rowIndex, 1].Value.ToStringNN().Trim();

        //            val = cells[rowIndex, 15].Value.ToStringNN().Trim();
        //            int tedarikciId = -1;

        //            if (val != "")
        //                tedarikciId = dsIplik.Tables[4].Select("Unvan = '" + val + "'")[0][0].ToIntNN();

        //            int renkId = -1;
        //            string renkKodu = cells[rowIndex, 16].Value.ToStringNN().Trim();
        //            string renk = cells[rowIndex, 17].Value.ToStringNN().Trim();
        //            string fRenkKodu = "";
        //            string fRenk = "";

        //            if (renkKodu != "" || renk != "")
        //            {
        //                if (renkKodu == "")
        //                    fRenkKodu = "Kod is null";
        //                else
        //                    fRenkKodu = "Kod = '" + renkKodu + "'";

        //                if (renk == "")
        //                    fRenk = "Renk is null";
        //                else
        //                    fRenk = "Renk = '" + renk + "'";

        //                sql = "select RenkId from IplikRenk where " + fRenkKodu + " and " + fRenk;

        //                dt = Data.DM.ExecuteDataTableByQuery(sql);
        //                if (dt.Rows.Count == 1)
        //                    renkId = dt.Rows[0]["RenkId"].ToIntNN();
        //                else
        //                {
        //                    if (renkKodu == "")
        //                        sql = "insert into IplikRenk(Renk) select '" + renk + "'";
        //                    else if (renk == "")
        //                        sql = "insert into IplikRenk(Kod) select '" + renkKodu + "'";
        //                    else
        //                        sql = "insert into IplikRenk(Kod,Renk) select '" + renkKodu + "' , '" + renk + "'";

        //                    renkId = Data.DM.ExecuteDataTableByQuery(sql + " select scope_identity()").Rows[0][0].ToIntNN();
        //                }
        //            }

        //            val = cells[rowIndex, 19].Value.ToStringNN().Trim();
        //            int boyahaneId = -1;
        //            if (val != "")
        //                boyahaneId = dsIplik.Tables[5].Select("Boyahane = '" + val + "'")[0][0].ToIntNN();

        //            sql = "insert into Iplik(IplikGrupId) select " + iplikGrupId + " select SCOPE_IDENTITY()";
        //            int iplikId = Data.DM.ExecuteDataTableByQuery(sql).Rows[0][0].ToIntNN();



        //            string lot = cells[rowIndex, 18].Value.ToStringNN().Trim();
        //            int cuvalBot = cells[rowIndex, 20].Value.ToIntNN();
        //            int KG = cells[rowIndex, 22].Value.ToIntNN();


        //            string fTag = "Tag = null";

        //            if (kod != "")
        //                fTag = "Tag= '" + kod + "'";


        //            sql = "update Iplik set Tag= '" + kod + "'";

        //            if (tedarikciId != -1)
        //                sql += " , TedarikciId=" + tedarikciId;

        //            if (renkId != -1)
        //                sql += " , RenkId=" + renkId;

        //            if (boyahaneId != -1)
        //                sql += " , BoyahaneId=" + boyahaneId;

        //            if (lot != "")
        //                sql += " , Lot='" + lot + "'";
        //            if (cuvalBot > 0 - 1)
        //                sql += " , CuvalBot=" + cuvalBot;
        //            if (KG > 0)
        //                sql += " , KG=" + KG;

        //            sql += " where IplikId =" + iplikId;
        //            Data.DM.ExecuteDataTableByQuery(sql);



        //        }
        //    }
        //}

        //private static void ElyafEkle(OpenFileDialog ofd)
        //{
        //    DataSet dsElyaf = Data.DM.ExecuteDataSet("GetDSElyaf");

        //    using (ExcelPackage pack = new ExcelPackage(new FileInfo(ofd.FileName)))
        //    {
        //        ExcelWorksheet ws = pack.Workbook.Worksheets[1];
        //        ExcelRange cells = ws.Cells;

        //        object[,] vals = (object[,])cells.Value;


        //        int row = vals.GetLength(0);
        //        int col = vals.GetLength(1);


        //        for (int rowIndex = 2; rowIndex < row + 1; rowIndex++)
        //        {
        //            System.Diagnostics.Debug.WriteLine(rowIndex.ToString());
        //            string val = cells[rowIndex, 1].Value.ToStringNN().Trim();

        //            int cinsId = -1;
        //            string fCinsId = "";

        //            cinsId = dsElyaf.Tables[0].Select("Cins = '" + val + "'")[0][0].ToIntNN();
        //            fCinsId = "ElyafCinsId = " + cinsId;


        //            val = cells[rowIndex, 2].Value.ToStringNN().Trim();
        //            int kesitId = -1;
        //            string fKesitId = "";

        //            if (val != "")
        //            {
        //                kesitId = dsElyaf.Tables[1].Select("Kesit = '" + val + "'")[0][0].ToIntNN();
        //                fKesitId = "ElyafKesitId = " + kesitId;
        //            }
        //            else
        //                fKesitId = "ElyafkesitId is null";



        //            string kalinlik = cells[rowIndex, 3].Value.ToStringNN().Trim();
        //            string fKalinlik = "";

        //            if (kalinlik != "")
        //                fKalinlik = "Kalinlik = '" + kalinlik + "'";
        //            else
        //                fKalinlik = "Kalinlik is null";



        //            string uzunluk = cells[rowIndex, 4].Value.ToStringNN().Trim();
        //            string fuzunluk = "";

        //            if (uzunluk != "")
        //                fuzunluk = "Uzunluk = '" + uzunluk + "'";
        //            else
        //                fuzunluk = "Uzunluk is null";




        //            val = cells[rowIndex, 5].Value.ToStringNN().Trim();
        //            int parlaklikId = -1;
        //            string fParlaklikId = "";

        //            if (val != "")
        //            {
        //                parlaklikId = dsElyaf.Tables[2].Select("Parlaklik = '" + val + "'")[0][0].ToIntNN();
        //                fParlaklikId = "ElyafParlaklikId = " + parlaklikId;
        //            }
        //            else
        //                fParlaklikId = "ElyafParlaklikId is null";




        //            val = cells[rowIndex, 6].Value.ToStringNN().Trim();
        //            int cekimId = -1;
        //            string fCekimId = "";

        //            if (val != "")
        //            {
        //                if (val == "XS")
        //                    val = "AR-XS";

        //                cekimId = dsElyaf.Tables[3].Select("Cekim = '" + val + "'")[0][0].ToIntNN();
        //                fCekimId = "ElyafCekimId = " + cekimId;
        //            }
        //            else
        //                fCekimId = "ElyafCekimId is null";



        //            val = cells[rowIndex, 7].Value.ToStringNN().Trim();
        //            int kullanimId = -1;
        //            string fKullanimId = "";

        //            if (val != "")
        //            {
        //                kullanimId = dsElyaf.Tables[4].Select("Kullanim = '" + val + "'")[0][0].ToIntNN();
        //                fKullanimId = "ElyafKullanimId = " + kullanimId;
        //            }
        //            else
        //                fKullanimId = "ElyafKullanimId is null";




        //            string aciklama = cells[rowIndex, 8].Value.ToStringNN().Trim();
        //            string faciklama = "";

        //            if (aciklama != "")
        //                faciklama = "Aciklama = '" + aciklama + "'";
        //            else
        //                faciklama = "Aciklama is null";





        //            string sql = "select * from ElyafGrup where " + fCinsId + " and " + fKesitId + " and " + fKalinlik + " and " + fuzunluk
        //                + " and " + fParlaklikId
        //                + " and " + fCekimId
        //                + " and " + fKullanimId
        //                + " and " + faciklama;

        //            int elyafGrupId = -1;


        //            DataTable dt = Data.DM.ExecuteDataTableByQuery(sql);
        //            if (dt.Rows.Count == 1)
        //                elyafGrupId = dt.Rows[0]["ElyafGrupId"].ToIntNN();
        //            else
        //            {
        //                sql = "insert into ElyafGrup(ElyafCinsId) select null select SCOPE_IDENTITY()";
        //                elyafGrupId = Data.DM.ExecuteDataTableByQuery(sql).Rows[0][0].ToIntNN();
        //            }

        //            sql = "update ElyafGrup set GrupKodu='EL." + elyafGrupId.ToString().PadLeft(3, '0') + "', ElyafCinsId= " + cinsId;

        //            if (kesitId != -1)
        //                sql += " , ElyafKesitId=" + kesitId;

        //            if (kalinlik != "")
        //                sql += " , Kalinlik='" + kalinlik + "'";

        //            if (uzunluk != "")
        //                sql += " , Uzunluk='" + uzunluk + "'";

        //            if (parlaklikId != -1)
        //                sql += " , ElyafparlaklikId=" + parlaklikId;

        //            if (cekimId != -1)
        //                sql += " , ElyafcekimId=" + cekimId;

        //            if (kullanimId != -1)
        //                sql += " , ElyafkullanimId=" + kullanimId;

        //            if (aciklama != "")
        //                sql += " , aciklama='" + aciklama + "'";

        //            sql += " where ElyafGrupId =" + elyafGrupId;
        //            Data.DM.ExecuteDataTableByQuery(sql);





        //            string kod = cells[rowIndex, 9].Value.ToStringNN().Trim();

        //            val = cells[rowIndex, 10].Value.ToStringNN().Trim();
        //            int tedarikciId = -1;

        //            if (val != "")
        //                tedarikciId = dsElyaf.Tables[5].Select("Unvan = '" + val + "'")[0][0].ToIntNN();

        //            int renkId = -1;
        //            string renkKodu = cells[rowIndex, 11].Value.ToStringNN().Trim();
        //            string renk = cells[rowIndex, 12].Value.ToStringNN().Trim();
        //            string fRenkKodu = "";
        //            string fRenk = "";

        //            if (renkKodu != "" || renk != "")
        //            {


        //                if (renkKodu == "")
        //                    fRenkKodu = "Kod is null";
        //                else
        //                    fRenkKodu = "Kod = '" + renkKodu + "'";

        //                if (renk == "")
        //                    fRenk = "Renk is null";
        //                else
        //                    fRenk = "Renk = '" + renk + "'";

        //                sql = "select RenkId from ElyafRenk where " + fRenkKodu + " and " + fRenk;

        //                dt = Data.DM.ExecuteDataTableByQuery(sql);
        //                if (dt.Rows.Count == 1)
        //                    renkId = dt.Rows[0]["RenkId"].ToIntNN();
        //                else
        //                {
        //                    if (renkKodu == "")
        //                        sql = "insert into ElyafRenk(Renk) select '" + renk + "'";
        //                    else if (renk == "")
        //                        sql = "insert into ElyafRenk(Kod) select '" + renkKodu + "'";
        //                    else
        //                        sql = "insert into ElyafRenk(Kod,Renk) select '" + renkKodu + "' , '" + renk + "'";

        //                    renkId = Data.DM.ExecuteDataTableByQuery(sql + " select scope_identity()").Rows[0][0].ToIntNN();
        //                }
        //            }

        //            val = cells[rowIndex, 13].Value.ToStringNN().Trim();
        //            int boyahaneId = -1;

        //            if (val != "")
        //                boyahaneId = dsElyaf.Tables[6].Select("Boyahane = '" + val + "'")[0][0].ToIntNN();

        //            sql = "insert into Elyaf(ElyafGrupId) select " + elyafGrupId + " select SCOPE_IDENTITY()";
        //            int elyafId = Data.DM.ExecuteDataTableByQuery(sql).Rows[0][0].ToIntNN();



        //            sql = "update Elyaf set Tag= '" + kod + "'";

        //            if (tedarikciId != -1)
        //                sql += " , TedarikciId=" + tedarikciId;

        //            if (renkId != -1)
        //                sql += " , RenkId=" + renkId;

        //            if (boyahaneId != -1)
        //                sql += " , BoyahaneId=" + boyahaneId;


        //            sql += " where ElyafId =" + elyafId;
        //            Data.DM.ExecuteDataTableByQuery(sql);



        //        }
        //    }
        //}

        private void btnFasonIplik_ItemClick(object sender, ItemClickEventArgs e)
        {
            ShowMdiChildForm(typeof(FasonIplik));
        }

        private void btnImalKarti_ItemClick(object sender, ItemClickEventArgs e)
        {
            ShowMdiChildForm(typeof(ImalatKartlari));
        }

        private void btnIadeOnay_ItemClick(object sender, ItemClickEventArgs e)
        {
            ShowMdiChildForm(typeof(IadeOnay));
        }

        private void btnRaf_ItemClick(object sender, ItemClickEventArgs e)
        {
            AppSession.MainForm.ShowMdiChildForm(typeof(Shelf));
        }

        private void btnTopluGuncelleme_ItemClick(object sender, ItemClickEventArgs e)
        {
            AppSession.MainForm.ShowMdiChildForm(typeof(TopluMetrajGuncelleme));
        }

        public void Notify(string message)
        {
            this.Info = message;
        }

        private void btnQuery_ItemClick(object sender, ItemClickEventArgs e)
        {
            AppSession.MainForm.ShowMdiChildForm(typeof(Query));
        }

        private void btnSatinalma_ItemClick(object sender, ItemClickEventArgs e)
        {
            AppSession.MainForm.ShowMdiChildForm(typeof(Satinalma));
        }

        private void btnDepo_ItemClick(object sender, ItemClickEventArgs e)
        {
            AppSession.MainForm.ShowMdiChildForm(typeof(Depo));
        }

        private void btnIplikler_ItemClick(object sender, ItemClickEventArgs e)
        {
            AppSession.MainForm.ShowMdiChildForm(typeof(Iplik.Iplikler));
        }

        private void btnSiparisler_ItemClick(object sender, ItemClickEventArgs e)
        {
            AppSession.MainForm.ShowMdiChildForm(typeof(Siparisler), 2);
        }

        private void btnCariAktarma_ItemClick(object sender, ItemClickEventArgs e)
        {
            AppSession.MainForm.ShowMdiChildForm(typeof(CariAktarma));
        }

        private void btnBarkodKontrol_ItemClick(object sender, ItemClickEventArgs e)
        {
            AppSession.MainForm.ShowMdiChildForm(typeof(BarkodKontrol));
        }

        private void btnCikisSepeti_ItemClick(object sender, ItemClickEventArgs e)
        {
            AppSession.MainForm.ShowMdiChildForm(typeof(Cikislar.CikisSepet));
        }

        private void btnPidionClear_ItemClick(object sender, ItemClickEventArgs e)
        {
            string result = AppSession.MainForm.black.ClearAllData();
            XtraMessageBox.Show(Language.Stock.PidionResult + result, Language.Uyari, MessageBoxButtons.OK, MessageBoxIcon.Information);
        }

        private void btnIpleriRafla_ItemClick(object sender, ItemClickEventArgs e)
        {
            throw new ApplicationException("Birden çok giriş var!!");
            //Data.TAM.IplikTableAdapter.Fill(Data.DB.Iplik);

            //Dictionary<int, int> dagilim = AppSession.MainForm.black.GetIpYerlesim();
            //foreach (KeyValuePair<int, int> pair in dagilim)
            //{
            //    //XtraMessageBox.Show("RollId:" + pair.Key + " , ShelfId:" + pair.Value);
            //    AkerDB.IplikRow dr = Data.DB.Iplik.FindByIplikId(pair.Key);
            //    dr.ShelfId = pair.Value;
            //    Data.TAM.IplikTableAdapter.Update(dr);
            //}

            //btnPidionClear.PerformClick();
        }

        private void btnArtikelRafla_ItemClick(object sender, ItemClickEventArgs e)
        {
            ArtikelRafla();
        }

        public void ArtikelRafla()
        {
            Data.TAM.StokLinesTableAdapter.Fill(Data.DB.StokLines);

            Dictionary<int, int> dagilim = AppSession.MainForm.black.GetRafYerlesim();
            foreach (KeyValuePair<int, int> pair in dagilim)
            {
                //XtraMessageBox.Show("RollId:" + pair.Key + " , ShelfId:" + pair.Value);
                AkerDB.StokLinesRow slRow = (AkerDB.StokLinesRow)Data.DB.StokLines.Select("RollId = " + pair.Key)[0];
                slRow.ShelfId = pair.Value;
                Data.TAM.StokLinesTableAdapter.Update(slRow);
            }

            if (XForm.Ask("Cihazın içeriği temizlensin mi?") == System.Windows.Forms.DialogResult.OK)
                btnPidionClear.PerformClick();
        }

        private void btnCikislar_ItemClick(object sender, ItemClickEventArgs e)
        {
            AppSession.MainForm.ShowMdiChildForm(typeof(Cikislar.Cikislar), 1);
        }

        private void btnSiparisTakipVeCikis_ItemClick(object sender, ItemClickEventArgs e)
        {
            ShowMdiChildForm(typeof(Uretim.SiparisTakipVeCikis), 2, -1);
        }

        private void btnCikisEmirleri_ItemClick(object sender, ItemClickEventArgs e)
        {
            ShowMdiChildForm(typeof(Cikislar.Cikislar), 2);
        }

        private void btnCikisTakip_ItemClick(object sender, ItemClickEventArgs e)
        {
            ShowMdiChildForm(typeof(Cikislar.Cikislar), 3);
        }

        private void btnDahiliSevkKabul_ItemClick(object sender, ItemClickEventArgs e)
        {
            ShowMdiChildForm(typeof(Cikislar.DahiliSevkKabul));
        }

        private void btnUreticiBarkod_ItemClick(object sender, ItemClickEventArgs e)
        {
            ShowMdiChildForm(typeof(UreticiBarkod));
        }

        private void btnHareketler_ItemClick(object sender, ItemClickEventArgs e)
        {
            ShowMdiChildForm(typeof(Hareketler));
        }
    }
}